package org.iabako.client.tools;

import com.google.gwt.i18n.client.Dictionary;

import java.util.MissingResourceException;

/**
 * TODO javadoc
 * Date: 14/12/13
 * Time: 17:18
 */
public class Messages {

    public static String getLabel(String labelKey) {
        Dictionary messages = Dictionary.getDictionary("messages");
        try {
            return messages.get(labelKey);
        } catch (MissingResourceException e) {
            return labelKey;
        }
    }

    public static String getLabel(String labelKey, String... params) {
        int i = 0;
        String labelWithParams = Messages.getLabel(labelKey);
        for (String p : params) {
            labelWithParams = labelWithParams.replace("#" + i, getLabel(p));
            labelWithParams = labelWithParams.replace("{" + i + "}", getLabel(p));
            i++;
        }
        return labelWithParams;
    }
}
